package com.yex.constant;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@Slf4j
public class AppConstant {
	public final static String CODE = "code";
	public final static String MESSAGE = "msg";
	public final static String TIME = "time";
	public final static String DATA = "data";
	public final static String ORDERID = "orderId";
	public final static int maxResults = 10;
	public final static String TOTAL_PAGE = "totalPage";
	public final static String CUR_PAGE = "curPage";

	public final static String Result = "result";
	public final static String Value = "value";
	public final static String LoginToken = "loginToken";
	public final static String CurrentPage = "currentPage";
	public final static String TotalPage = "totalPage";
	public final static String LastUpdateTime = "lastUpdateTime";
	public final static String Fid = "fid";

	public static HashMap<String, Integer> actionMap = new HashMap<String, Integer>();
	private static final Logger LOGGER = LoggerFactory.getLogger(AppConstant.class);
	static {
		int i = 0;
		actionMap.put("Invalidate", i++);// 无效

		actionMap.put("UserLogin", i++);// 登录
		actionMap.put("UserRegister", i++); // 注册
		actionMap.put("SendMessageCode", i++);
		actionMap.put("SendMailCode", i++);
		actionMap.put("FindLoginPassword", i++);

		actionMap.put("GetCoinListInfo", i++);// 每个币种的基础信息
		actionMap.put("GetVersion", i++);// 获取服务端最小版本号
		actionMap.put("GetMarketData", i++);// 行情
		actionMap.put("GetNews", i++);// 新闻
		actionMap.put("GetMyCenter", i++);// 个人中心
		actionMap.put("GetAbout", i++);// 个人中心
		actionMap.put("GetMarketDepth", i++);// 市场深度
		actionMap.put("RechargeBanks", i++);

		actionMap.put("AfterWeiXinLogin", i++);
		actionMap.put("AfterQQLogin", i++);
		actionMap.put("market", i++);
		actionMap.put("period", i++);
		actionMap.put("lastDealPrice", i++);
		actionMap.put("lang", i++);
		actionMap.put("GetIndexData", i++);
		actionMap.put("otcCoinList", i++);
		actionMap.put("otcEntrustList", i++);
		actionMap.put("otcMarket", i++);
		actionMap.put("bankList", i++);
		actionMap.put("GetMarketDepthSimple", i++);
		actionMap.put("GetIndexDataSimple", i++);

		// 需要token
		i = 201;
		actionMap.put("GetAccountInfo", i++); // 账号信息，用户信息+交易账号+放款账号信息
		actionMap.put("GetBtcRechargeListRecord", i++);// 虚拟币充值，返回充值地址和记录
		actionMap.put("GetEntrustInfo", i++);// 委托订单
		actionMap.put("CancelEntrust", i++);// 取消订单
		actionMap.put("BtcTradeSubmit", i++);// 下单
		actionMap.put("TradePassword", i++);// 交易密码
		actionMap.put("GetIntrolinfo", i++);// 提成明细
		actionMap.put("GetIntrolDetail", i++);

		actionMap.put("ViewValidateIdentity", i++);// 查看认证信息

		actionMap.put("ValidateIdentity", i++);

		actionMap.put("RechargeCny", i++);

		actionMap.put("bindPhone", i++);
		actionMap.put("veinLogin", i++);
		actionMap.put("UnbindPhone", i++);
		actionMap.put("ChangebindPhone", i++);

		actionMap.put("GetWithdrawBankList", i++);
		actionMap.put("SetWithdrawCnyBankInfo", i++);
		actionMap.put("WithDrawCny", i++);
		actionMap.put("GetWithdrawBtcAddress", i++);
		actionMap.put("SetWithdrawBtcAddr", i++);
		actionMap.put("WithdrawBtcSubmit", i++);
		actionMap.put("changePassword", i++);
		actionMap.put("GetAllRecords", i++);
		actionMap.put("GetSettingLogs", i++);
		actionMap.put("GetLoginLogs", i++);
		actionMap.put("PostQuestion", i++);
		actionMap.put("DelQuestion", i++);
		actionMap.put("ListQuestions", i++);
		actionMap.put("GeRechargeBankList", i++);
		actionMap.put("GetQuestionTypeList", i++);
		actionMap.put("getSecurity", i++);
		actionMap.put("googleAuth", i++);
		actionMap.put("getBindGoogle", i++);
		actionMap.put("bindMail", i++);

		actionMap.put("GetScoreLogs", i++);
		actionMap.put("getScoreRule", i++);
		actionMap.put("getLevelRule", i++);

		actionMap.put("getCoinAddress", i++);
		actionMap.put("DetelCoinAddress", i++);
		actionMap.put("DeleteBankAddress", i++);
		actionMap.put("ValidateKyc", i++);

		actionMap.put("optional", i++);
		actionMap.put("optionalList", i++);
		actionMap.put("optionalSort", i++);
		actionMap.put("sendBindPhoneMailCode", i++);
		actionMap.put("validatePhone", i++);
		actionMap.put("iosDisableSendCoin", i++);
		actionMap.put("iosDisableActivity", i++);
        actionMap.put("getAwardAfterDoneTask", i++);
        actionMap.put("taskList", i++);
        actionMap.put("logout", i++);
		actionMap.put("clock", i++);
		actionMap.put("userClockList", i++);
		actionMap.put("clockRuleList", i++);
		actionMap.put("clockAccount", i++);
		actionMap.put("otcEntrustUserList", i++);
		actionMap.put("suspendOtcEntrust", i++);
		actionMap.put("cancelOtcEntrust", i++);
		actionMap.put("otcUserInfo", i++);
		actionMap.put("saveOtcEntrust", i++);
		actionMap.put("otcAccount", i++);
		actionMap.put("rotationOtcWallet", i++);
		actionMap.put("userPayAccount", i++);
		actionMap.put("payAccountCode", i++);
		actionMap.put("settingPayAccount", i++);
		actionMap.put("uploadUserPhoto", i++);
		actionMap.put("otcOrder", i++);
		actionMap.put("otcOrderInfo", i++);
		actionMap.put("otcArbitration", i++);
		actionMap.put("otcReceivables", i++);
		actionMap.put("otcPayment", i++);
		actionMap.put("otcCancelOrder", i++);
		actionMap.put("otcAftersale", i++);
		actionMap.put("otcContact", i++);
		actionMap.put("otcUploadVoucher", i++);
		actionMap.put("otcUploadVoucherImg", i++);
		actionMap.put("bindPhoneAndEmail", i++);
		actionMap.put("otcOrderDetails", i++);
		actionMap.put("otcVoucher", i++);
		actionMap.put("bindNewGoogle", i++);
	};

	public synchronized static Integer getInteger(String action) {
		try {
			Integer actionInteger = actionMap.get(action);

			if (actionInteger == null) {
				actionInteger = 0;
			}

			return actionInteger;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	public static int getInt(String param) {
		int ret = 0;
		try {
			ret = Integer.parseInt(param.trim());
		} catch (Exception e) {
		}
		return ret;
	}


	public static JSONObject getUnknownError(Exception e) {
		if(e != null){
			e.printStackTrace();
		}

		JSONObject jsonObject = new JSONObject();
		jsonObject.put(CODE, -10001);
		jsonObject.put(MESSAGE, ("failedInfo"));
		return jsonObject;
	}

	public static JSONObject getUnknownError(HttpServletRequest request, Exception e) {
		log.error("==getUnknownError==:",e);
		log.info("===info==getUnknownError=={}",e.getMessage());
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(Result, true);
		jsonObject.put(CODE, -10003);
		jsonObject.put(Value,( "failedInfo"));
		return jsonObject;
	}
}